﻿using System;
using System.Windows.Forms;

namespace PhiStore.ExampleCodes.PhiLog
{
    public partial class PhiLogUI : Form
    {
        Timer t = new Timer();
        PhiLogSpammer spam;

        public PhiLogUI()
        {
            InitializeComponent();
            t.Tick += new EventHandler(UpdateThroughPut);
            t.Interval = 1000;
            t.Start();
        }

        void UpdateThroughPut(object sender, EventArgs e)
        {
            if (spam != null)
            {
                this.throughput.Text = spam.ThroughPut.ToString("N2") + " ops/s";
            }
        }

        private void StartStop_Click(object sender, EventArgs e)
        {
            if (StartStop.Text == "Start")
            {
                StartStop.Text = "Stop";
                spam = new PhiLogSpammer((uint)replications.Value, 
                    encryptConnect.Checked, 
                    compress.Checked, 
                    encryptObjects.Checked,
                    use2PC.Checked);
            }
            else
            {
                if (spam != null)
                    spam.STOP();

                spam = null;
                StartStop.Text = "Start";
            }
        }

        private void PhiLogUI_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (spam != null)
            {
                spam.STOP();
            }
        }
    }
}
